<template>
  <div>
    <div class="pageheader">
      <XHeader :left-options="{backText:''}" :title="xheader.title" class="XHeader"></XHeader>
    </div>
    <div class="page">
      <div style="margin-top: 12px;">
        <div style="margin-bottom: 70px">
          <div class="block" v-for="(item,index) in addressList" :key="index">
            <div class="itembox" @click="onSelect(item)">
              <div class="header">
                <span class="title">{{item.true_name}}</span>
              </div>
              <div class="address">{{item.area_info+item.address}}</div>
            </div>
          </div>
        </div>
      </div>

      <div class="block sumit">
        <button @click="onAdd">添加新地址</button>
      </div>
    </div>
  </div>
</template>

<script>
  import Me from '@/dll/me'

  export default {
    name: 'addressSelect',
    data () {
      return {
        xheader: {
          title: '选择地址'
        },
        addressList: []
      }
    },
    created () {
    },
    activated () {
      this.getList()
    },
    methods: {
      onSelect (item) {
        this.globalData.tempAddressSelect = item
        this.$router.back()
      },
      onAdd () {
        this.$router.push({ name: 'addressEdit' })
      },

      async getList () {
        this.$vux.loading.show({
          text: '加载中'
        })
        let res = await Me.getMeAddressList()
        this.$vux.loading.hide()
        if (res.code == 0) {
          this.addressList = res.data.addresslist
        }
      }
    }
  }
</script>

<style lang="less" scoped>
  page {
    padding-bottom: 78px;
  }

  .itembox {
    padding: 24px;
    background-color: #fff;
  }

  .itembox .header {
    display: flex;
    justify-content: space-between;
    font-size: 16px;
    color: #351009;
    line-height: 22px;
  }

  .itembox .address {
    font-size: 12px;
    color: #351009;
    line-height: 17px;
    margin-top: 12px;
  }

  .itembox .query {
    display: flex;
    align-items: center;
    margin-top: 24px;
  }

  .itembox .query .label {
    flex: 1;
    display: block;
    font-size: 14px;
    color: #351009;
    line-height: 20px;
  }

  .itembox .query .edit {
    margin-left: 12px;
    display: block;
    font-size: 14px;
    line-height: 28px;
    height: 28px;
    width: 64px;
    text-align: center;
    color: #351009;
    box-sizing: border-box;
    background-color: transparent;
    border: 1px solid #d4d4d4;
  }

  .sumit {
    background-color: #fbf8f7;
    padding-bottom: 32px;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    box-sizing: border-box;
  }

  .sumit button {
    font-size: 16px;
  }
</style>
